package com.oocl.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.oocl.pojo.Customer;
import com.oocl.service.CustomerService;
import com.oocl.service.impl.CustomerServiceFactory;

@Controller
public class CustomerController {
	private CustomerService cSer;
	
	public CustomerController() {
		
		cSer =CustomerServiceFactory.getInstance();
	}

	@ResponseBody
	@RequestMapping(value="/addcustomer", consumes="application/json")
	public Customer addCustomer(@RequestBody Customer c){
		Customer customer = cSer.addCustomer(c);
		return customer;
	}
	
	@ResponseBody
	@RequestMapping(value="/list")
	public List<Customer> getList(){
		List<Customer> list = cSer.findAllCustomers();
		return list;
	}
	
	@ResponseBody
	@RequestMapping(value="/delete", consumes="application/json")
	public Customer deleteCustomer(@RequestBody Customer c){
		Customer customer = cSer.deleteCustomer(c.getId());
		return customer;
	}
	
	@ResponseBody
	@RequestMapping(value="/update", consumes="application/json")
	public Customer updateCustomer(@RequestBody Customer c){
		Customer customer = cSer.updateCustomer(c);
		return customer;
	}
	
	@ResponseBody
	@RequestMapping(value="/loadone")
	public Customer loadCustomer(String id){
		Customer customer = cSer.FindCustomerById(id);
		return customer;
	}
	
}














